$(document).ready(function(){
    
    $(".approveBuy").live("click", function(){
        var totalPrice=0;
		
		  $('.qouantity').each(function(){
            totalPrice += parseInt($(this).attr('price'))*parseInt($(this).val());
        });
      
		  $.ajax(
        {
			 
            url:'inc/buyCartProducts.php',
            data:"bellValue="+totalPrice,
            type: 'post',
            success: function(j){
                $('#cartProductsArea').html(j);     
            //                        $('.infoDiv').html("<img src=\"images/loading.gif\" width=\"50px\" style=\"display:block; margin:auto; border-radius:3px;\"/>");
            //                $('.infoDiv').html(j);
            }
        });

		
       $('.qouantity').each(function(){
            var currentProduct = $(this).attr('product');//product id
            var currentProductQuantity = $(this).val();
            $.ajax(
            {
                url:'inc/addHistory.php',
                data:"productID="+currentProduct+"&productQuantity="+currentProductQuantity,
                type: 'post',
                success: function(j){
                //                        $('.infoDiv').html("<img src=\"images/loading.gif\" width=\"50px\" style=\"display:block; margin:auto; border-radius:3px;\"/>");
                //                $('.infoDiv').html(j);
                }
            });
        });
		
		
      

      
    });// end approve paying
    
    
    
    $('.discardBuy').live("click",function(){
//        alert('ss');
        $.ajax(
        {
            url:'inc/discardAllCart.php',
            data:"productID=null",
            type: 'post',
            success: function(j){
                //                        $('.infoDiv').html("<img src=\"images/loading.gif\" width=\"50px\" style=\"display:block; margin:auto; border-radius:3px;\"/>");
                //                $('.infoDiv').html(j);
                $('#cartProductsArea').html(j);
            }
        });
        $.ajax(
        {
            url:'inc/getCartCount.php',
            data:"id="+deleteProduct,
            type: 'post',
            success: function(j){
                $(".cartNav").html(j)
            }
        });
    });
    $('.deleteFromCart').live("click",function(){
        var deleteProduct = $(this).attr('content');
        
      
        $.ajax(
        {
            url:'inc/discardFromCart.php',
            data:"productID="+deleteProduct,
            type: 'post',
            success: function(j){
                //                        $('.infoDiv').html("<img src=\"images/loading.gif\" width=\"50px\" style=\"display:block; margin:auto; border-radius:3px;\"/>");
                //                $('.infoDiv').html(j);
                $('#cartProductsArea').html(j);
            }
        });
        $.ajax(
        {
            url:'inc/getCartCount.php',
            data:"id="+deleteProduct,
            type: 'post',
            success: function(j){
                $(".cartNav").html(j)
            }
        });
    });
});
